/**
 * Created by Bruce on 2016/7/15.
 */

window.onload = function () {
    /*删除弹框*/
    popWin();
    /*更改数字*/
    changeNum();
};
/**/
var popWin = function () {
    /*点击删除按钮  显示弹出框*/
    var deleteBtns = document.querySelectorAll(".delete_box");/*所有的删除盒子*/
    var jdWin = document.querySelector(".jd_win");
    var jdWinBox = jdWin.querySelector(".jd_win_box");
    var cancel = document.querySelector(".cancel");/*删除按钮*/
    var deleteUp = null;
    for(var i = 0; i < deleteBtns.length; i++) {
        deleteBtns[i].onclick = function () { /*每一个删除盒子  绑定点击事件*/
            deleteUp = this.querySelector(".delete_up");
            jdWin.style.display = "block";  /*点击删除盒子显示弹出层*/
            jdWinBox.classList.add('myBounceInDown');/*盒子动态出现*/

            deleteUp.style.webkitTransition = "all 1s";/*过渡效果*/
            deleteUp.style.transition = "all 1s";

            deleteUp.style.webkitTransformOrigin = "0 5px"; /*设置原点*/
            deleteUp.style.transformOrigin = "0 5px";

            deleteUp.style.webkitTransform = "rotate(-30deg) translateY(2px)";/*设置角度和位移*/
            deleteUp.style.transform = "rotate(-30deg) translateY(2px)";
        }
    }
    cancel.onclick = function () { /*点击取消  隐藏弹出层  删除盒子回归初始状态  */
        jdWin.style.display = "none";
        deleteUp.style.webkitTransform = "none";
        deleteUp.style.transform = "none";
    }

};

/*更改数量*/
function changeNum() {
    var changes = document.querySelectorAll(".change_num");
    for(var i= 0; i < changes.length; i++) {
        var change = changes[i];
        var changeBtns = change.querySelectorAll("span");
        var minusBtn = changeBtns[0];
        var plusBtn = changeBtns[1];
        plusBtn.onclick = function() {
            var input = this.parentNode.querySelector("input");
            var num = input.value;
            num++;
            input.value = num;

        }

        minusBtn.onclick = function() {
            var input = this.parentNode.querySelector("input");
            var num = input.value;
            if(num > 0) {
                num--;
                input.value = num;
            }
            
        }
    }
   
}
